package com.ddyx.common.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author cj
 */
public class DateUtil {

	public static SimpleDateFormat format_ymd_hms = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public static SimpleDateFormat format_ymd = new SimpleDateFormat("yyyy-MM-dd");
	
	public static String getNow(){
		return format_ymd_hms.format(new Date());
	}
	
	public static String getToday_Ymd(){
		return format_ymd.format(new Date());
	}
	
	public static String getFirstDayOfThisWeek_Ymd(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		int d = 0;
		if(cal.get(Calendar.DAY_OF_WEEK)==1){
			d = -6;
		}else{
			d = 2-cal.get(Calendar.DAY_OF_WEEK);
		}
		cal.add(Calendar.DAY_OF_WEEK, d);
		return format_ymd.format(cal.getTime());
	}
	
	public static String getLastDayOfThisWeek_Ymd(){
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		int d = 0;
		if(cal.get(Calendar.DAY_OF_WEEK)==1){
			d = -6;
		}else{
			d = 2-cal.get(Calendar.DAY_OF_WEEK);
		}
		cal.add(Calendar.DAY_OF_WEEK, d);
		cal.add(Calendar.DAY_OF_WEEK, 6);
		return format_ymd.format(cal.getTime());
	}
}
